import store from "@/store"

import { getAll  } from "@/api/admin/dictionary";

export const useDictionaryStore = defineStore("dictionary", () => {
    const dict = ref([])
    
    const bookDict = computed(()=> {
      return dict.value['book']
    })

    const refreshDict = async () => {
        const res =  await getAll();
        dict.value = res.result
    }

    const initDict = async () => {
      if(dict.value.length == 0) {
        await refreshDict()
      }
  }
  
    return { dict, bookDict,
      initDict, refreshDict }
})


  /** 在 setup 外使用 */
export function useDictionaryStoreHook() {
  return useDictionaryStore(store)
}
